package com.quanyan.runningriding.web.running;


import com.quanyan.api.APIResponse;
import com.quanyan.common.utils.StringUtil;
import com.quanyan.common.validation.base.Insert;
import com.quanyan.runningriding.entity.vo.run.req.RunUserVo;
import com.quanyan.runningriding.entity.vo.run.resp.UserLevelInfo;
import com.quanyan.runningriding.service.RunUserService;
import com.quanyan.runningriding.util.RunEnum;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * RunMusicController
 *
 * @author Tu Chun
 * @date 2016/8/23
 */
@RestController
@RequestMapping(value = "/api/run")
public class RunUserController {
    @Autowired
    private RunUserService runUserService;
    private static final Logger logger = LoggerFactory.getLogger(RunUserController.class);

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public APIResponse<?> login(@RequestBody @Validated(Insert.class) RunUserVo runUserVo) throws UnsupportedEncodingException {
        return runUserService.login(runUserVo);
    }


    @RequestMapping(value = "/showUserLevel", method = RequestMethod.POST)
    public APIResponse<UserLevelInfo> showUserLevel(@RequestBody Map<String,Object> paramMap) {
        String userId=MapUtils.getString(paramMap, "userId");
        if(StringUtil.isBlankOrNull(userId)) {
            APIResponse.returnFail(RunEnum.PARAMETER_NOT_VALID);
        }
        return runUserService.showUserLevel(userId);
    }



}
